﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script language="javascript" type="text/javascript">

        function loadjscssfile(filename, filetype, callback) {
            var fileref;
            if (filetype == "js") { //if filename is a external JavaScript file
                fileref = document.createElement('script');
                fileref.setAttribute("type", "text/javascript");
                fileref.setAttribute("src", filename);
            }
            else if (filetype == "css") { //if filename is an external CSS file
                fileref = document.createElement("link");
                fileref.setAttribute("rel", "stylesheet");
                fileref.setAttribute("type", "text/css");
                fileref.setAttribute("href", filename);
            }

            if (fileref) {//typeof fileref != "undefined"
                document.getElementsByTagName("head")[0].appendChild(fileref);
                if (document.all) {//ie
                    fileref.onreadystatechange = function () {
                        if (fileref.readyState == 'loaded' || fileref.readyState == 'complete') {
                            if (callback) { callback(); }
                        }
                    }
                }
                else {//others
                    fileref.onload = function () {
                        if (callback) { callback(); }
                    }
                }
            }
        }

        function removejscssfile(filename, filetype) {
            var targetelement = (filetype == "js") ? "script" : (filetype == "css") ? "link" : "none";  //determine element type to create nodelist from
            var targetattr = (filetype == "js") ? "src" : (filetype == "css") ? "href" : "none";  //determine corresponding attribute to test for
            var allsuspects = document.getElementsByTagName(targetelement);
            for (var i = allsuspects.length; i >= 0; i--) { //search backwards within nodelist for matching elements to remove
                if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
                    allsuspects[i].parentNode.removeChild(allsuspects[i]);  //remove element by calling parentNode.removeChild()
            }
        }

        google.load("jquery", "1.7.1");
        loadjscssfile("jquery-1.7.1.min.js", "js", btnOnClick);
        //alert("ok");
        //$("#unn").val("ok");
        function btnOnClick() {
            loadjscssfile("myScript.js", "js");
            $("#unn").val("ok");
        }
    </script>
</head>
<body>
    <input name="un" id="unn" />
    <input type="button" onclick="btnOnClick()" />
</body>
</html>
